package com.itheima.day08.myMap.test5;

import java.text.Collator;
import java.util.Locale;

public class Student implements Comparable<Student> {
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student s) {
        // 比较年龄
        int result = this.age - s.age;
        if (result != 0)
            return result;

        // 比较姓名
        char[] arr = this.name.toCharArray();
        boolean boo = false;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] >= 'A' && arr[i] <= 'Z') {
                boo = true;
                break;
            } else if (arr[i] >= 'a' && arr[i] <= 'z') {
                boo = true;
                break;
            }
        }
        // 英文字典排序
        if (boo == true) {
            result = this.name.compareTo(s.name);
            return result == 0 ? 1 : result;
        }
        // 中文字典排顺序
        // 创建中文比较器
        Collator ins = Collator.getInstance(Locale.CHINESE);
        result = ins.compare(this.name, s.name);
        return result == 0 ? 1 : result;

    }
}
